<?php
$mysql = mysqli_connect('localhost', 'root', 'root', 'db_blog');

if (!$mysql) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

function showAllOfBlog($flag): array
{
    global $mysql;
    $res = mysqli_query($mysql, "SELECT id_blog, title, author, publish FROM tb_blog WHERE del_flag = '$flag'");
    $list = array();
    while ($row = mysqli_fetch_assoc($res)) {
        $list[] = $row;
    }
    return $list;
}

function showBlogById($id): array
{
    global $mysql;
    $res = mysqli_query($mysql, 'SELECT * FROM tb_blog WHERE id_blog = ' . $id);
    return mysqli_fetch_assoc($res);
}


